package com.mahjong.server.model;

import org.apache.mina.core.session.IoSession;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.mahjong.server.common.EmPlayerStatus;
import com.mahjong.server.component.logic.entity.PlayerMahjong;

/**
 * 玩家类，把User封装为一个Player，可看做是一个客户端，可进行交互
 * 
 * @author Simple
 * @date 2013-3-13 下午04:40:06
 * @Description TODO
 */
@Component(value="player")
@Scope("prototype")
public class Player {

  private int id;

  private String nickName;// 昵称

  private int roomId;// 房间id

  private EmPlayerStatus status=EmPlayerStatus.FREE;// 状态

  private int position;// 位置

  private User user;// 用户信息

  private PlayerMahjong mahjongData=new PlayerMahjong();// 打牌过程中的一些数据

  private IoSession session;// session;

  private int onlineTime;// 在线时间

  private boolean isOnline;// 是否在线

  private int idleTime;// 空闲时间

  public Player() {
  }

  public Player(IoSession session) {
    this.setSession(session);
  }

  // 心跳
  public void heartbeat() {
    System.out.println("idleTime+1");
    this.idleTime+=1;// 空闲时间+1
    if(this.isOnline == false) {
      return;
    }
    System.out.println("onlineTime+1");
    this.onlineTime+=1;// 在线时间+1
    this.user.setOnlineTime(this.user.getOnlineTime() + 1);// 用户在线时间
  }

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id=id;
  }

  public int getRoomId() {
    return roomId;
  }

  public void setRoomId(int roomId) {
    this.roomId=roomId;
  }

  public int getPosition() {
    return position;
  }

  public void setPosition(int position) {
    this.position=position;
  }

  public void setSession(IoSession session) {
    this.session=session;
  }

  public IoSession getSession() {
    return session;
  }

  public void setUser(User user) {
    this.user=user;
  }

  public User getUser() {
    return user;
  }

  public void setNickName(String nickName) {
    this.nickName=nickName;
  }

  public String getNickName() {
    return nickName;
  }

  public void setStatus(EmPlayerStatus status) {
    this.status=status;
  }

  public EmPlayerStatus getStatus() {
    return status;
  }

  public void setMahjongData(PlayerMahjong mahjongData) {
    this.mahjongData=mahjongData;
  }

  public PlayerMahjong getMahjongData() {
    return mahjongData;
  }

  public void setOnlineTime(int onlineTime) {
    this.onlineTime=onlineTime;
  }

  public int getOnlineTime() {
    return onlineTime;
  }

  public void setOnline(boolean isOnline) {
    this.isOnline=isOnline;
  }

  public boolean isOnline() {
    return isOnline;
  }

  public void setIdleTime(int idleTime) {
    this.idleTime=idleTime;
  }

  public int getIdleTime() {
    return idleTime;
  }

  @Override
  public String toString() {
    return "[Player] [id=" + id + "&idleTime=" + idleTime + "&isOnline=" + isOnline + "&nickName=" + nickName + "&onlineTime="
      + onlineTime + "&roomId=" + roomId + "&session=" + session + "&status=" + status + "]";
  }
}
